//
//  StatusCellTopView.m
//  OC-微博
//
//  Created by Apple on 15/11/13.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "StatusCellTopView.h"
#import "StatusViewModel.h"
#import "Status.h"
@interface StatusCellTopView()
//头像
@property (nonatomic, strong) UIImageView *iconView;
//姓名
@property (nonatomic, strong) UILabel *nameLabel;
//会员图标
@property (nonatomic, strong) UIImageView *memberIconView;
// 认证图标
@property (nonatomic, strong) UIImageView *vipIconView;
// 时间标签
@property (nonatomic, strong) UILabel *timeLabel;
// 来源标签
@property (nonatomic, strong) UILabel *sourceLabel;

@end

@implementation StatusCellTopView
#pragma mark /*******************  懒加载  *******************/
- (void)setVie:(StatusViewModel *)vie{
   
    _vie = vie;
    // 姓名
    self.nameLabel.text = vie.statu.user.screen_name;
   // 头像
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:vie.statu.user.profile_image_url]placeholderImage:[UIImage imageNamed:@"avatar_default_big"] options:SDWebImageRetryFailed | SDWebImageRefreshCached];
    //会员图标
   
self.memberIconView.image = vie.userMemberImage;
    // 认证图标
    self.vipIconView.image = vie.userVipImage;
    // 时间
    self.timeLabel.text =  vie.statu.created_at;
}
#pragma mark /*******************  构造函数  *******************/
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}
#pragma mark /*******************  设置界面  *******************/
- (void)setupUI {
    self.backgroundColor = [[UIColor alloc]initWithWhite:0.95 alpha:1.0];

    [self addSubview: self.iconView];
    [self addSubview: self.nameLabel];
    [self addSubview: self.memberIconView];
    [self addSubview: self.vipIconView];
    [self addSubview: self.timeLabel];
    [self addSubview: self.sourceLabel];
    // 2. 自动布局
[self.iconView makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.top).offset(StatusCellMargin);
            make.left.equalTo(self.left).offset(StatusCellMargin);
            make.width.equalTo(StatusCellIconWidth);
            make.height.equalTo(StatusCellIconWidth);
        }];
        [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconView.top);
            make.left.equalTo(self.iconView.right).offset(StatusCellMargin);
        }];
        [self.memberIconView makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.nameLabel.top);
            make.left.equalTo(self.nameLabel.right).offset(StatusCellMargin);
        }];
        [self.vipIconView makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.iconView.right);
            make.centerY.equalTo(self.iconView.bottom);
        }];
        [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.iconView.bottom);
            make.left.equalTo(self.iconView.right).offset(StatusCellMargin);
        }];
        [self.sourceLabel makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.timeLabel.bottom);
            make.left.equalTo(self.timeLabel.right).offset(StatusCellMargin);
        }];

}
#pragma mark /*******************  懒加载控件  *******************/
//懒加载
-(UIImageView *)iconView {
    
    if (_iconView == nil) {
        _iconView = [UIImageView setImageName:@"avatar_default_big"];
    }
    return _iconView;
}
//懒加载
-(UILabel *)nameLabel {
    
    if (_nameLabel == nil) {
        _nameLabel = [UILabel setLabelTitle:@"王老五" textColor:[UIColor darkGrayColor] labelFont:14 screenInset:0];
    }
    return _nameLabel;
}
//懒加载
-(UIImageView *)memberIconView {
    
    if (_memberIconView == nil) {
        _memberIconView = [UIImageView setImageName:@"common_icon_membership_level1"];
    }
    return _memberIconView;
}
//懒加载
-(UIImageView *)vipIconView {
    
    if (_vipIconView == nil) {
        _vipIconView = [UIImageView setImageName:@"avatar_vip"];
    }
    return _vipIconView;
}
//懒加载
-(UILabel *)timeLabel {
    
    if (_timeLabel == nil) {
        _timeLabel = [UILabel setLabelTitle:@"现在" textColor:[UIColor orangeColor] labelFont:11 screenInset:0];
    }
    return _timeLabel;
}
//懒加载
-(UILabel *)sourceLabel {
    
    if (_sourceLabel == nil) {
        _sourceLabel = [UILabel setLabelTitle:@"来源" textColor:[UIColor darkGrayColor] labelFont:11 screenInset:0];    }
    return _sourceLabel;
}
@end
